import Vue from "vue";
import VueRouter from "vue-router";
import $store from "../store/index.js";
Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        redirect: "/User/Login",
    },
    {
        path: "/User",
        name: "User",
        component: () => import("@/User/User.vue"),
        children: [
            {
                path: "Login",
                name: "Login",
                component: () => import("@/User/Login.vue"),
                beforeEnter(_, __, next) {
                    if ($store.state.user.user.info) {
                        next({ name: "Logined" });
                    } else {
                        next();
                    }
                },
            },
            {
                path: "Logined",
                name: "Logined",
                component: () => import("@/User/Logined.vue"),
                beforeEnter(_, __, next) {
                    if ($store.state.user.user.info) {
                        next();
                    } else {
                        next({ name: "Login" });
                    }
                },
            },
        ],
    },
    {
        path: "/SnippetsSearch",
        name: "SnippetsSearch",
        component: () => import("@/Snippets/SnippetsSearch.vue"),
    },
    {
        path: "/quickDeliver",
        name: "quickDeliver",
        component: () => import("@/Deliver/quickDeliver.vue"),
    },
    {
        path: "/NodeBook",
        name: "NodeBook",
        component: () => import("@/NodeBook/index.vue"),
        beforeEnter(to, from, next) {
            window.Preload.getRunkit().then(() => next());
        },
    },
    {
        path: "/test",
        name: "test",
        component: () => import("@/vant-plus/test.vue"),
    },
];

export default new VueRouter({
    routes,
});
